package RabbitMq.config;

import RabbitMq.Component.RabbitConsumerChannelAwareMessage;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;

/**
 * @ClassName AckConfig
 * @Description TDD
 * @Author 混沌酱
 * @Date 2023-10-13 16:49
 * @Version 1.0
 **/
@Configuration
public class AckConfig {

    @Resource
    private CachingConnectionFactory connectionFactory;

    @Resource
    private RabbitConsumerChannelAwareMessage rabbitConsumerChannelAwareMessage;

    @Bean
    public SimpleMessageListenerContainer simpleMessageListenerContainer(){
        SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(connectionFactory);
        // 设置消费者个数，当前设置为1
        listenerContainer.setConcurrentConsumers(1);
        listenerContainer.setMaxConcurrentConsumers(1);
        listenerContainer.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        // 设置一个已存在的队列
        listenerContainer.setQueueNames("reliable_queue");

        listenerContainer.setMessageListener(rabbitConsumerChannelAwareMessage);

        return listenerContainer;
    }

}
